package cn.edu.zzuli.admin.service.impl;

import cn.edu.zzuli.admin.mapper.OrderMapper;
import cn.edu.zzuli.admin.mapper.UserMapper;
import cn.edu.zzuli.admin.service.OrderService;
import cn.edu.zzuli.model.dto.admin.OrderDetailsDto;
import cn.edu.zzuli.model.dto.admin.OrderDto;
import cn.edu.zzuli.model.entity.OfferOrder;
import cn.edu.zzuli.model.entity.User;
import cn.edu.zzuli.model.vo.order.OrderChooseVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, OfferOrder> implements OrderService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Page<OrderDto> queryList(Integer page, Integer limit, Integer oid) {
        Page<OrderDto> condPage = new Page<>(page,limit);
        QueryWrapper<OrderDto> wrapper = new QueryWrapper<>();
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("nick_name");

        wrapper.orderByAsc("refund").orderByAsc("oid");
        if (oid != null) {
            wrapper.eq("oid",oid);
        }
        Page<OrderDto> orderDtoPage = baseMapper.selectListByTypeId(condPage,wrapper);


        List<OrderDto> records = orderDtoPage.getRecords();
        for (OrderDto record : records) {
            String nickName = userMapper.getNickName(record.getRuid());
            record.setType(this.changeType(record.getType()));
            record.setRNickName(nickName);
        }
        return orderDtoPage;
    }


    private String changeType(String type) {
        if(type == "0"){
            type = "万能任务";
        }else if(type == "1"){
            type = "取快递";
        }else if(type == "2"){
            type = "寄快递";
        }else if(type == "3"){
            type = "食堂带饭";
        }else{
            type = "校园陪跑";
        }
        return type;
    }

    @Override
    public OrderDetailsDto getDetails(OrderChooseVo detailsVo) {
        //查询字段
        OfferOrder offerOrder = baseMapper.selectById(detailsVo.getOid());
//        String oNickName = userMapper.getNickName(detailsVo.getOuid());
//        String rNickName = userMapper.getNickName(detailsVo.getRuid());
//        //获取详情信息对象
//        OrderDetailsDto orderDetailsDto = new OrderDetailsDto(detailsVo.getOuid(),oNickName,
//                detailsVo.getRuid(),rNickName,offerOrder.getTitle(),offerOrder.getSendPlace(),offerOrder.getPickPlace(),
//                offerOrder.getDescribed(),offerOrder.getBounty());
        return null;
    }
}
